programming4us
           
 
 
Windows Phone

Windows Phone 7 with Silverlight : Working with the Phone

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
11/25/2010 3:41:45 PM
This first application is a program that can be pretty self-sufficient, but not applications are like that. Most applications will want to interact with the phone’s operation system to work with other parts of the phone. From within your application you may want to make a phone call, interact with the user’s contacts, take a pictures, etc. The Windows Phone 7 SDK calls these types of interactions Tasks. Tasks let you leave an application (and optionally return) to perform a number of phone-specific tasks. Some of the most common of these are:
  • CameraCaptureTask

  • EmailAddressChooserTask

  • EmailComposeTask

  • PhoneCallTask

  • SearchTask

  • WebBrowserTask

These tasks allow you to launch a task for the user to do. In some of these tasks (e.g. CameraCaptureTask, EmailAddressChooserTask), once the task is complete the user expects to return to your application; while in others (e.g. SearchTask) the user may be navigating to a new activity (and may come back via the back key, but may not).

Let’s start with a simple task, the SearchTask. In our code, create an event handler for the MouseLeftButtonUp event on theEllipse. Then inside the handler for the MouseLeftButtonUp event, you can create an instance of the SearchTask, set the search criteria and call Show to launch the task:

...
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
...

theEllipse.MouseLeftButtonUp += new
MouseButtonEventHandler(theEllipse_MouseLeftButtonUp);

}

void theEllipse_MouseLeftButtonUp(object sender,
MouseButtonEventArgs e)
{
SearchTask task = new SearchTask();
task.SearchQuery = "Windows Phone 7";
task.Show();
}

...
}

If you run your application, you’ll see that when you tap on theEllipse it will launch the Phone’s Search using the Search Query that you supplied (as shown in Figure 1).

Figure 1. The Search Task (SearchTask.bmp)


While this sort of simple task is useful, the more interesting story is being able to call tasks that return to your application. For example, let’s pick an e-mail address from the phone and show it in our application. The big challenge here is when we launch our application, we may get tombstoned (or deactivated). Remember that on the phone, only one application can be running at a time. In order to have our task wired up when our application is activated (remember, it can be deactivated or even unloaded if necessary), we have to have our task at the page or application level and wired up during construction. So in our page, create a class level field and wire up the Completed event at the end of the constructor for it like so:

public partial class MainPage : PhoneApplicationPage
{

EmailAddressChooserTask emailChooser = new EmailAddressChooserTask();

// Constructor
public MainPage()
{
...

emailChooser.Completed += new
EventHandler<EmailResult>(emailChooser_Completed);
}

...
}

In the event handler, we can simply show the e-mail chosen using the MessageBox API:

...
void emailChooser_Completed(object sender, EmailResult e)
{
MessageBox.Show(e.Email);
}
...

Now we need to call the chooser. To do this, let’s highjack the event that gets called when theEllipse is tapped. Just comment out the old SearchTask code and add a call to the emailChooser’s Show method like so:

...
void theEllipse_MouseLeftButtonUp(object sender,
MouseButtonEventArgs e)
{
//SearchTask task = new SearchTask();
//task.SearchQuery = "Windows Phone 7";
//task.Show();

// Get an e-mail from the user's Contacts
emailChooser.Show();
}
...

Once you run the application, a list of contacts will be shown (if you have any) and let you pick a contact (and which address if there is more than one) as shown in Figure 2.

Figure 2. Choosing a Contact’s Email (ChooseAnEmail.bmp)


When the chooser is launched, you will notice that the debugger stops in Visual Studio. This is expected as our application is being deactivated (tombstoned) so the debugger no longer has a process to hold on to. Once the user picks the contact, the phone returns to your application. You will notice the emulator shows a black screen. This is your cue (you have 10 seconds) to relaunch the app so you can re-active your application. Once you’ve relaunched your application, your debugging will continue where you left off. The event handler should be called when it is returned to the application as shown in Figure 3.

Figure 3. Showing the selected email in a MessageBox (ShowingTheEmail.bmp)


Other -----------------
- Writing Your First Phone Application - Adding Code (part 2)
- Writing Your First Phone Application - Adding Code (part 1)
- Developing Applications for Windows Phone 7 : Designing with Blend
- Developing Applications for Windows Phone 7 : Creating a New Project
- Developing Applications for Windows Phone 7 with Silverlight : Preparing Your Machine
- Windows Phone 7 : Picking Ringtones and Alerts
- Windows Phone 7 : Changing Themes and Wallpaper
- Windows Phone 7 : Customizing the Start Screen
- Windows Phone 7 : Connecting to a Wi-Fi Hotspot
- Windows Phone 7 : Setting Up Facebook
- Windows Phone 7 : Setting Up E-Mail and Your Calendar
- Windows Phone 7 : Taking a Quick Tour (part 2)
- Windows Phone 7 : Taking a Quick Tour (part 1)
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us